package com.ijunfu.detail.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 *
 * @Title  : shutdownNow
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/24 14:20
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class _06Main {

    public static void main(String[] args) {

        // 1. 创建线程池
        ExecutorService pool = Executors.newFixedThreadPool(5);

        try {
            // 2. 使用线程池-业务逻辑
            IntStream.range(0,10).forEach((idx)->pool.execute(()->log.info("No.{}", idx)));
        } catch (Exception ex) {
            log.error("{}", ex.getMessage(), ex);
        } finally {
            // 3. 销毁线程池-只等待正在运行的任务执行完毕后，关闭线程池
            pool.shutdown();
        }
    }
}
